package dts_tcp

import (
	"github.com/sirupsen/logrus"
	"time"
)

type Log struct {
	Level string    `json:"level"`
	Log   string    `json:"log"`
	At    time.Time `json:"at"`
}

var debug bool

func PushLog(level logrus.Level, log string) {
	if level >= I && !debug {
		return
	}
	text, err := level.MarshalText()
	if err != nil {
		return
	}
	LoadCallsFilterCodeRun(CodeLogs, Log{Level: string(text), Log: log, At: time.Now()})
}

func PushLog2(params ...any) {
	var (
		level = logrus.ErrorLevel
		log   string
	)

	for _, param := range params {
		switch param.(type) {
		case logrus.Level:
			level = param.(logrus.Level)
		case string:
			log = param.(string)
		}
	}

	if level >= I && !debug {
		return
	}
	text, err := level.MarshalText()
	if err != nil {
		return
	}
	LoadCallsFilterCodeRun(CodeLogs, Log{Level: string(text), Log: log, At: time.Now()})
}
